<?php
/**
 * 
 * @package	educME
 * @copyright (c) Jose Raul Perez 2011 under GPL
 */
 
abstract class moodleApplication extends EyeosApplicationExecutable {
    public static function __run(AppExecutionContext $context, MMapResponse $response) {

        // This code is executed when the application is initiated
        
        // put in memory, the files we could use
        // TODO LAZY LOAD!!?!?!?
        $buffer = '';

        $itemsPath = EYE_ROOT . '/' . APPS_DIR . '/moodle';

        $dir = new DirectoryIterator($itemsPath);
        foreach($dir as $file) {
            $fileName = $file->getBasename();
            if (!$file->isDot() && $fileName{0} != '.' && strchr($fileName, '.js')) {
                $buffer .= file_get_contents($itemsPath . '/' . $fileName);
            }
        }

        $response->appendToBody($buffer);




    }

    public static function login() {
        $user["username"] = $_SESSION["user"];
        $user["password"] = $_SESSION["password"];
        return $user;
    }
	
    // return assignment and submission
    public static function getAssignment($id) {
        require_once(dirname(__FILE__) . "/client/functions/assignments.php");

        $assigment = new stdClass();
        $assigment->assignment = getAssignment($id);
        $assigment->submission = getSubmission($id);
        
	return json_encode($assigment);
    }
	
    // update assignment
    public static function updateSubmission($submission) {
	require_once(dirname(__FILE__) . "/client/functions/assignments.php");

        return updateSubmission($submission);
    }

    public static function close($params) {
        EyeosApplicationExecutable::close($params);
    }
}
?>